package org.emergency.framework.dao.oa.Impl;

import java.util.List;

import org.emergency.framework.dao.HibernateBaseDao;
import org.emergency.framework.dao.oa.ITbUserRoleEntityDAO;
import org.emergency.framework.model.TbUserRoleEntity;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

/**
 * 
 * @author Administrator
 *
 */
@Repository("tbUserRoleEntityDAO")
public class TbUserRoleEntityDAO extends HibernateBaseDao<TbUserRoleEntity> implements ITbUserRoleEntityDAO{
	private static final Logger log = LoggerFactory
			.getLogger(TbUserRoleEntityDAO.class);

	protected void initDao() {
		// do nothing
	}


	public List<TbUserRoleEntity> findByExample(TbUserRoleEntity instance) {
		log.debug("finding TbUserRoleEntity instance by example");
		try {
			List<TbUserRoleEntity> results = (List<TbUserRoleEntity>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbUserRoleEntity instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TbUserRoleEntity as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all TbUserRoleEntity instances");
		try {
			String queryString = "from TbUserRoleEntity";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbUserRoleEntity merge(TbUserRoleEntity detachedInstance) {
		log.debug("merging TbUserRoleEntity instance");
		try {
			TbUserRoleEntity result = (TbUserRoleEntity) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbUserRoleEntity instance) {
		log.debug("attaching dirty TbUserRoleEntity instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbUserRoleEntity instance) {
		log.debug("attaching clean TbUserRoleEntity instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbUserRoleEntityDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TbUserRoleEntityDAO) ctx.getBean("TbUserRoleEntityDAO");
	}
}